package com.chenglu.android.index.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chenglu.android.R;
import com.chenglu.android.common.net.Constant;
import com.chenglu.android.common.utils.PxUtils;
import com.chenglu.android.goodsinfo.infoutils.GoodsInfoUtils;
import com.chenglu.android.index.bean.NearbyShopBean;
import com.chenglu.android.index.bean.PageListBean;

import java.util.List;

import io.reactivex.rxjava3.internal.schedulers.NewThreadWorker;

/**c
 * @author: lyj
 * @Created: by Copyright 2023/3/13 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：首页图片的adapter数据
 */
public class NearbyShopAdapter extends BaseQuickAdapter<NearbyShopBean.Data.Records, BaseViewHolder> {

    private Context mContext ;
    public NearbyShopAdapter(@Nullable Context context, List<NearbyShopBean.Data.Records> data) {
        super(R.layout.item_nearby_shop, data);
        this.mContext = context;

    }



    @Override
    protected void convert(@NonNull BaseViewHolder helper, NearbyShopBean.Data.Records item) {


        if(item!=null){
//            LogUtils.e("picadapter中的数据"+item.toString());
            TextView tvNearbyShop = helper.getView(R.id.tv_nearby_shop);
            TextView tvDistance = helper.getView(R.id.tv_distance);
            RecyclerView recyclerView = helper.getView(R.id.rv_item_shop);

            tvNearbyShop.setText(item.getShopsName());
            tvDistance.setText("距离您"+item.getDistance()+"km");
            recyclerView.setLayoutManager(new LinearLayoutManager(mContext,RecyclerView.HORIZONTAL,false));
            NearbyShopItemAdapter shopItemAdapter = new NearbyShopItemAdapter(mContext,item.getGoodsVOList());
            recyclerView.setAdapter(shopItemAdapter);
            shopItemAdapter.notifyDataSetChanged();

            shopItemAdapter.setOnItemClickListener(new OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    NearbyShopBean.Data.Records.GoodsVOList goodsVOList = shopItemAdapter.getData().get(position);

                    if(goodsVOList.getShopsTypeId()==Constant.typeIdRestaurant || goodsVOList.getShopsTypeId()==Constant.typeIdMinimart
                            || goodsVOList.getShopsTypeId() == Constant.typeIdPharmaceuticals ||goodsVOList.getShopsTypeId()==Constant.typeIdBreed){
                        //跳转餐饮外卖首页
                        GoodsInfoUtils.goodsRestantInfo(mContext,goodsVOList.getId(),goodsVOList.getShopsTypeId());
                    }else {
                        //跳转商超的店铺首页
                        GoodsInfoUtils.goodsInfo(mContext,goodsVOList.getId(),goodsVOList.getShopsTypeId());
                    }
                }
            });
        }
    }
}
